import os


def rename_folder(dataset_dir, category):
    for ZY in os.listdir(dataset_dir):
        p1 = os.path.join(dataset_dir, ZY)
        if not "ZY" in ZY:
            continue
        for H in os.listdir(p1):
            p2 = os.path.join(p1, H)
            if not "H" in H:
                continue
            p3 = os.path.join(p2, category)
            if not os.path.isdir(p3):
                continue
            for N in os.listdir(p3):
                p4 = os.path.join(p3, N)
                if not "N" in N:
                    continue
                for S in os.listdir(p4):
                    p5 = os.path.join(p4, S)
                    if not "S" in S:
                        continue
                    for s in os.listdir(p5):
                        p6 = os.path.join(p5, s)
                        if not "s" in s:
                            continue
                        for T in os.listdir(p6):
                            p7 = os.path.join(p6, T)
                            if not "T" in T:
                                continue
                            if os.path.isdir(os.path.join(p7, "object_delta_pose")):
                                if not os.path.isdir(os.path.join(p7, "obj_delta_pose")):
                                    os.system("mv {} {}".format(os.path.join(p7, "object_delta_pose"), os.path.join(p7, "obj_delta_pose")))
                                else:
                                    print(p7)
                                    os.system("rm -r {}".format(os.path.join(p7, "object_delta_pose")))


if __name__ == "__main__":
    categories = [
        "C2",
        "C5",
        "C7",
        "C12",
    ]
    for C in categories:
        rename_folder("/localdata_sdd/HOI4D_Sim", C)